package com.caishi.lkx.order.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzw.common.entity.IBaseMapper;
import com.caishi.lkx.order.model.OrderModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author by keray
 * date:2021/7/14 4:26 下午
 */
public interface OrderMapper extends IBaseMapper<OrderModel, String> {

    @Select("select count(*) from or_order as ors,or_order_detail as ord" +
            " where ors.id = ord.order_id" +
            " and ors.type = 2" +
            " and ors.order_status <> 30" +
            " and ors.user_id = #{group}" +
            " and ord.entity_id = #{courseId}" +
            ""
    )
    int groupHaveSubjectCourse(@Param("group") String group, @Param("courseId") String courseId);

    @Select("select ors.* from or_order as ors,or_order_detail as ord" +
            " where ors.id = ord.order_id" +
            " and ors.type = 2" +
            " and ors.user_id = #{group}" +
            " and ord.entity_id = #{courseId}" +
            ""
    )
    OrderModel groupSubCourseOrder(@Param("group") String group, @Param("courseId") String courseId);




    long searchCount(@Param("param") Map<String, Object> param);
    @Select("select o.* from `order` as o")
    List<OrderModel> distributeOrderList(Map<String,Object> params);

    /**
     * <p>
     * <h3>作者 keray</h3>
     * 订单查询
     * </p>
     *
     * @param offset
     * @param size
     * @param param  orderSn 订单号
     *               type 订单类型
     *               orderStatus 订单状态
     *               paymentStatus 订单支付状态
     *               paymentType 订单支付方式
     *               deviceType 订单支付设备
     *               createdStartTime 订单创建时间
     *               createdEndTime
     *               payStartTime 订单支付时间
     *               payEndTime 订单支付时间
     *               ids in的订单id列表
     *               userId 订单用户id
     *               userIds in的订单用户id
     *               noOrderStatus 排除的订单状态
     *
     * @return <p> {@link List < UserModel>} </p>
     * @throws
     */
    List<OrderModel> search(@Param("offset") Long offset, @Param("size") Long size, @Param("param") Map<String, Object> param,
                                   @Param("asc") List<String> asc,
                                   @Param("desc") List<String> desc);


    Long countAmount( @Param("param") Map<String, Object> param);

    Long selectMoney(@Param("param")Map<String, Object> param);


    IPage<OrderModel> openCourseList(Page<OrderModel> page, @Param("param") Map<String,Object> param);

    IPage<OrderModel> openCodeList(Page<OrderModel> page,@Param("param")Map<String,Object> param);

    List<Map> priceCountLine(@Param("param") Map<String, Object> param);
}
